// Copyright (c) 2005  CRIMERE (France).
// All rights reserved.
//
// This file is part of OPSC; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; version 2.1 of the License.
// See the file LICENSE.LGPL distributed with OSPC.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Author(s)     : Mercier Jean-Marc
//=========================================================================
/*! Modulus templated function.
	Actually, I did not find any proper modulus implementation, I had to provide one !
*/

#include <functional>

#if !defined(_Modulus_)
#define _Modulus_

	  namespace jmmath {
template<class _Tx, class _Ty>
		_Ty mod(const _Tx& _Left, const _Ty& _Right)
			{
				_Tx breakpoint_x(_Left % _Tx (_Right));
				_Ty breakpoint_y( _Ty (_Left) % _Right);
				if ( (_Ty) breakpoint_x == (_Tx) breakpoint_y )  // then safe classical %
				 return (breakpoint_x);
				return breakpoint_x + _Right;
			};
	  };
#endif
